<template>
	<view>
		<u-row customStyle="margin-bottom: 96px">
			<u-col span="12">
				<view>
					<u-navbar
					    title="个人简历"
						titleStyle="font-weight:bold"
					    :safeAreaInsetTop="true"
						:fixed="true"
						bgColor="#FFBE59"
						@leftClick="leftClick"
						@rightClick="rightClick"
					>
					    <view
					        class="u-nav-slot"
					        slot="left"
					    >
					        <u-icon
					            name="arrow-left"
					            size="20"
								color="black"
					        ></u-icon>
					    </view>
						<view
						    class="u-nav-slot"
						    slot="right"
						>
						    <u-icon
						        name="more-dot-fill"
						        size="24"
								color="black"
						    ></u-icon>
						</view>
					</u-navbar>
				</view>
			</u-col>
		</u-row>
		<u-row customStyle="margin-bottom: 0px">
			<u-col span="11" style="margin: 0 auto;">
				<view class="topStatus">
					<span style="font-size: 14px;float: left;">简历状态：</span>
					<span style="float: left;font-size: 14px;color: #ff8800;" v-if="this.stuResumeList.resumeState == 3">{{resumeState}}</span>
					<span style="float: left;font-size: 14px;color: #00e8e8;" v-if="this.stuResumeList.resumeState == 0">{{resumeState}}</span>
					<span style="float: left;font-size: 14px;color: #00b31a;" v-if="this.stuResumeList.resumeState == 1">{{resumeState}}</span>
					<span style="float: left;font-size: 14px;color: #e10000;" v-if="this.stuResumeList.resumeState == 2">{{resumeState}}</span>
					<div style="float: right;">
						<span style="font-size: 14px;color: #0B67F1;" @click="subState()" v-if="this.stuResumeList.resumeState == 3">提交{{' '}}</span>
						<span style="font-size: 14px;color: #0B67F1;" @click="subState()" v-if="this.stuResumeList.resumeState == 2">重新提交{{' '}}</span>
						<span style="font-size: 14px;color: #0B67F1;" @click="recordPage()">审核记录</span>
					</div>
				</view>
			</u-col>
		</u-row>
	<u-divider :dashed="true" ></u-divider>
		<div>
			<view>
					<u-action-sheet @select="selectClick" cancelText="取消" @close="endShow()" :actions="list" :closeOnClickOverlay="true" :closeOnClickAction="true" :show="show"></u-action-sheet>
			</view>
		</div>
		<u-modal :show="showConfirm" @confirm="confirmFunction()" @cancel="cancelFunction()" width="250px" :content='contentConfirm' :showCancelButton='true'></u-modal>
				<u-row customStyle="margin-bottom: 10px">
					<u-col span="11" style="margin: 0 auto;">
						<view class="resume bg-purple-light">
							<u-col span="12">
								<view class="resume-essential-information bg-purple-light" @click="essentialInformationFunction()">
									<u-col span="12">
										<view class="resume-full-name bg-purple-light">
											<h1>{{stu.stuName}}</h1>
											<u-icon class="edit-pen" name="edit-pen" color="#ADADAD" size="28"></u-icon>
										</view>
									</u-col>
									<u-col span="12">
										<view class="resume-content bg-purple-light">
											<span>{{this.schoolOuttime}}</span>年毕业-<span>{{this.stuAge}}</span>岁-<span>{{this.stuEducation}}</span>
										</view>
									</u-col>
								</view>
							</u-col>
						</view>
					</u-col>
				</u-row>
				<u-row customStyle="margin-bottom: 10px">
					<u-col span="11" style="margin: 0 auto;">
						<view class="resume bg-purple-light">
							<u-col span="12">
								<view class="job-intention bg-purple-light">
									<u-col span="12">
										<view class="job-intention-title bg-purple-light">
											<h3 style="float: left;">求职意向</h3>
											<u-icon class="job-intention-icon" name="plus-circle" color="#ADADAD" size="20" @click="jobIntentionFnuction('')"></u-icon>
										</view>
									</u-col>
									<div v-for="(item,index) in stuResumeList.positonIntentionList" @click="jobIntentionFnuction(item.id)">
										<u-col span="12">
											<view class="industry-salary bg-purple-light">
												<span style="font-weight:550;">{{item.positionTypeId}}</span>{{' '}}<span style="font-weight:550;font-size: 15px;">{{item.salaryExpectation}}</span>
												<u-icon class="industry-salary-icon" name="arrow-right" color="#ADADAD" size="16"></u-icon>
											</view>
										</u-col>
										<u-col span="12">
											<view class="industry-region bg-purple-light">
												<span style="font-size: 13px;color: #666666;">{{item.addressId}}</span>{{'  '}}<span style="font-size: 13px;color: #666666;">{{item.industryTypeId}}</span>
											</view>
										</u-col>
									</div>
								</view>
							</u-col>
						</view>
					</u-col>
				</u-row>
				<u-row customStyle="margin-bottom: 10px">
					<u-col span="11" style="margin: 0 auto;">
						<view class="resume bg-purple-light">
							<u-col span="12">
								<view class="educational-experience bg-purple-light">
									<u-col span="12">
										<view class="educational-experience-title bg-purple-light">
											<h3 style="float: left;">教育经历</h3>
											<u-icon class="educational-experience-icon" name="plus-circle" color="#ADADAD" size="20" @click="jumpEducationalExperience('')"></u-icon>
										</view>
									</u-col>
									<div v-for="(item,index) in stuResumeList.educationExperienceList" @click="jumpEducationalExperience(item.id)">
										<u-col span="12">
											<view class="school-name bg-purple-light">
												<span style="font-weight:bold;font-size: 15px;">{{item.schoolName}}</span>
												<u-icon class="school-name-icon" name="arrow-right" color="#ADADAD" size="16"></u-icon>
											</view>
										</u-col>
										<u-col span="12">
											<view class="school-content bg-purple-light">
												<span style="font-size: 13px;color: #666666;">{{item.schoolIntime}}{{' '}}-{{' '}}{{item.schoolOuttime}}</span>{{'  '}}<span style="font-size: 13px;color: #666666;">{{item.schoolMajor}}</span>
											</view>
										</u-col>
									</div>
								</view>
							</u-col>
						</view>
					</u-col>
				</u-row>
				<u-row customStyle="margin-bottom: 10px">
					<u-col span="11" style="margin: 0 auto;">
						<view class="resume bg-purple-light">
							<u-col span="12">
								<view class="work-experience bg-purple-light">
									<u-col span="12">
										<view class="work-experience-title bg-purple-light">
											<h3 style="float: left;">工作经历</h3>
											<u-icon class="work-experience-icon" name="plus-circle" color="#ADADAD" size="20" @click="workExperience('')"></u-icon>
										</view>
									</u-col>
									<div v-for="(item,index) in stuResumeList.workExperienceList" @click="workExperience(item.id)">
										<u-col span="12">
											<view class="corporate-name bg-purple-light">
												<span style="font-weight:bold;font-size: 15px;">{{item.enterpriseName}}</span>
												<u-icon class="corporate-name-icon" name="arrow-right" color="#ADADAD" size="16"></u-icon>
											</view>
										</u-col>
										<u-col span="12">
											<view class="corporate-post bg-purple-light">
												<span style="font-size: 13px;color: #666666;">{{item.workIntiime}}{{' '}}-{{' '}}{{item.workOuttime}}</span>{{'  '}}<span style="font-size: 13px;color: #666666;">{{item.positionName}}</span>
											</view>
										</u-col>
									</div>
								</view>
							</u-col>
						</view>
					</u-col>
				</u-row>
				<u-row customStyle="margin-bottom: 10px">
					<u-col span="11" style="margin: 0 auto;">
						<view class="resume bg-purple-light">
							<u-col span="12">
								<view class="project-experience bg-purple-light">
									<u-col span="12">
										<view class="project-experience-title bg-purple-light">
											<h3 style="float: left;">项目经历</h3>
											<u-icon class="project-experience-icon" name="plus-circle" color="#ADADAD" size="20" @click="projectExperience('')"></u-icon>
										</view>
									</u-col>
									<div v-for="(item,index) in stuResumeList.projectExperienceList" @click="projectExperience(item.id)">
										<u-col span="12">
											<view class="project-name bg-purple-light">
												<span style="font-weight:bold;font-size: 15px;">{{item.projectName}}</span>
												<u-icon class="project-name-icon" name="arrow-right" color="#ADADAD" size="16"></u-icon>
											</view>
										</u-col>
										<u-col span="12">
											<view class="project-time bg-purple-light">
												<span style="font-size: 13px;color: #666666;">{{item.projectStart}}{{' '}}-{{' '}}{{item.projectEnd}}</span>
											</view>
										</u-col>
									</div>
								</view>
							</u-col>
						</view>
					</u-col>
				</u-row>
			</view>
		</template>

<script>
	export default {
		data() {
			return {
				list: [
						{
							code:'1',
							name:'上传简历'
						},
						{
							code:'2',
							name:'下载简历'
						},
						{
							code:'3',
							name: '删除简历'
						},
					],
					show: false,
					stuResumeList:{},
					resumeState:"",
					stu:{},
					stuAge:'20',
					schoolOuttime:null,
					stuEducation:'本科',
					showConfirm:false,
					contentConfirm:'',
					}
				},
		created() {
			this.loading();
		},
		methods: {
			//跳转审核记录页
			recordPage(){
				uni.navigateTo({
					url: '/pages/service/practicaltrainingservice/resume/auditRecords?stuId='+this.stu.stuId,
				});
			},
			//简历提交操作：修改简历状态
			subState(){
				this.$axios.get('/resume/employmentResume/updateResumeState?id='+this.stuResumeList.id+'&stateNum='+0).then((res)=>{
					if(res.data.success){
						this.loading();
						uni.showToast({
							icon: 'success',
							position: 'bottom',
							title: '提交成功'
						});
					}else{
						uni.showToast({
							icon: 'error',
							position: 'bottom',
							title: '提交失败'
						});
					}
				})
			},
			//渲染前加载
			loading(){
				//从缓存中取出当前登录学生
				this.stu = uni.getStorageSync('stu');
				//根据学生id查询简历信息
				this.$axios.get('/resume/employmentResume/queryStuById?stuId='+this.stu.stuId).then((res)=>{
					if(res.data.result!=null && res.data.result!=undefined){
						this.stuResumeList = res.data.result;
						//根据出生日期计算年龄
						let stuBirthday = this.stuResumeList.employmentResumeBirthday;
						let d = new Date();
						var birthday=new Date(stuBirthday.replace(/-/g, "\/"));
						this.stuAge = d.getFullYear()-birthday.getFullYear()-((d.getMonth()<birthday.getMonth()|| d.getMonth()==birthday.getMonth() && d.getDate()<birthday.getDate())?1:0);
						
						//毕业时间
						if(this.stuResumeList.educationExperienceList[0]==undefined){
							let year = new Date()
							this.schoolOuttime=year.getFullYear()
						}else{
							this.schoolOuttime = this.stuResumeList.educationExperienceList[0].schoolOuttime.substring(0,4);
						}
						//学历
						let eduArr = ['初中及以下','高中','中专/中技','大专','本科','博士','硕士'];
						if(this.stuResumeList.educationExperienceList[0]==undefined){
							this.stuEducation="本科"
						}else{
							let education = this.stuResumeList.educationExperienceList[0].educationId;
							this.stuEducation = eduArr[education];
						}
						let resumeStateArr = ['审核中','已通过','未通过','待提交'];
						this.resumeState = resumeStateArr[this.stuResumeList.resumeState];
				
					}
				});
			},
			//文件上传
			upload(){
				/* 将this赋值_this */
				let _this=this
				/* 上传方法 */
				uni.chooseFile({
					/* 上传数量 */
					count: 1,
					/* 上传成功 */
					success(res) {
						/* 判断是否含有文件 */
						if (res.tempFilePaths.length > 0) {
							/* 上传地址 */
							let filePath = res.tempFilePaths[0]
							//进行上传操作
							uniCloud.uploadFile({
								filePath: filePath,
								/* 文件名 */
								cloudPath: res.tempFiles[0].name,
								onUploadProgress: function(progressEvent) {
									/* 文件id */
									var percentCompleted = Math.round(
									(progressEvent.loaded * 100) / progressEvent.total
									);
								},
								/* 上传成功 */
								success(res) {
									/* 回调文件地址 */
									_this.$axios.get('/resume/employmentResume/upResumeAttachment?resumeId='+_this.stuResumeList.id+"&resumeAttachment="+res.fileID).then((res)=>{
										if(res.data.success){
											_this.loading();
											uni.showToast({
												icon: 'success',
												position: 'bottom',
												title: '上传成功'
											});
										}else{
											uni.showToast({
												icon: 'success',
												position: 'bottom',
												title: '上传失败'
											});
										}
									})
								},
								/* 上传失败 */
								fail() {
									uni.showToast({
										icon: 'none',
										position: 'bottom',
										title: '网络连接错误'
									});
								},
							});
						}
					}
				});	
			},
			//左侧点击返回上一页面
			leftClick(){
				uni.reLaunch({
					url: '/pages/service/home/home',
				});
			},
			//右侧点击显示简历菜单
			rightClick(){
				this.show = true;
			},
			//简历附件下拉菜单
			selectClick(index){
				if(index.code==1){//上传简历
					this.upload();
				}else if(index.code==2){//下载简历
					if(this.stuResumeList.resumeAttachment!=""){
						this.openBrowser(this.stuResumeList.resumeAttachment);
					}else{
						uni.showToast({
							icon: 'error',
							position: 'bottom',
							title: '暂未上传简历'
						});
					}
				}else if(index.code==3){//删除简历
					if(this.stuResumeList.resumeAttachment!=""){
						this.delIntention();
					}else{
						uni.showToast({
							icon: 'error',
							position: 'bottom',
							title: '暂未上传简历'
						});
					}
				}
			},
			//删除简历的对话窗
			delIntention(){
				this.showConfirm = true;
				this.contentConfirm = "确认要删除吗？";
			},
			//对话框确认按钮
			confirmFunction(){
				this.showConfirm = false;
				this.$axios.get('/resume/employmentResume/upResumeAttachment?resumeId='+this.stuResumeList.id+"&resumeAttachment="+"").then((res)=>{
					if(res.data.success){
						this.loading();
						uni.showToast({
							icon: 'success',
							position: 'bottom',
							title: '删除成功'
						});
					}else{
						uni.showToast({
							icon: 'error',
							position: 'bottom',
							title: '删除失败'
						});
					}
				})
			},
			//对话框取消按钮
			cancelFunction(){
				this.showConfirm = false;
			},
			//简历下载
			 openBrowser(url){
				plus.runtime.openURL(url);
			},  
			//点击取消按钮时
			endShow(){
				this.show = false;//关闭上拉菜单
			},
			//基本信息表单页面
			essentialInformationFunction(){
				uni.navigateTo({
					url: '/pages/service/practicaltrainingservice/resume/essentialnformation',
				});
			},
			
			//求职意向表单页面
			jobIntentionFnuction(jobId){
				uni.navigateTo({
					url: '/pages/service/practicaltrainingservice/resume/jobIntention?jobId='+jobId+'&id='+this.stuResumeList.id,
				});
			},
			
			//教育经历表单页面
			jumpEducationalExperience(eduId){
				uni.navigateTo({
					url: '/pages/service/practicaltrainingservice/resume/educationalExperience?eduId='+eduId+'&resumeId='+this.stuResumeList.id,
				});
			},
			//工作经历表单页面
			workExperience(woId){
				uni.navigateTo({
					url: '/pages/service/practicaltrainingservice/resume/workExperience?woId='+woId+'&resumeId='+this.stuResumeList.id,
				});
			},
			//项目经历表单页面
			projectExperience(proId){
				uni.navigateTo({
					url: '/pages/service/practicaltrainingservice/resume/projectExperience?proId='+proId+'&resumeId='+this.stuResumeList.id,
				});
			},
	
		}
	}
</script>

<style lang="less">
	.resume{border-bottom: 1px solid #EEEEEE}
	.resume-essential-information{margin-left: 10px;}
	.resume-full-name h1 {float: left;font-size: 26px;}
	.resume-full-name .edit-pen{float: left;margin-top: 8px;margin-left: 4px;}
	.resume-content{margin-top: 4px;margin-bottom: 20px;}
	.job-intention,.educational-experience,.work-experience,.project-experience{margin-top: 10px;margin-left: 10px;}
	.job-intention-title .job-intention-icon,.educational-experience-title .educational-experience-icon,.work-experience .work-experience-title .work-experience-icon,.project-experience-title .project-experience-icon{margin-top: 3px;float: right;}
	.industry-salary,.school-name,.corporate-name,.project-name{margin-top: 12px;}
	.industry-salary .industry-salary-icon,.school-name .school-name-icon,.corporate-name .corporate-name-icon,.project-name .project-name-icon{margin-top: 3px;float: right;}
	.industry-region,.school-content,.corporate-post,.project-time{margin-top: 2px;margin-bottom: 20px;}
	.topStatus span{font-weight: bold;}
</style>
